package com.tzy.note.base.thread.state;

/**
 * 测试礼让线程
 * 礼让不一定成功，看cpu心情
 */
public class TestYield {
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "线程开始执行");
            Thread.yield(); //礼让
            System.out.println(Thread.currentThread().getName() + "线程停止执行");
        },"a").start();

        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "线程开始执行");
            Thread.yield(); //礼让
            System.out.println(Thread.currentThread().getName() + "线程停止执行");
        },"b").start();
    }
}
